package cn.com.headfree.workflow.dao.impl;

import cn.com.headfree.entity.*;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.vo.workflow.DbCount;
import cn.com.headfree.vo.workflow.ProcessListVo;
import cn.com.headfree.workflow.dao.IWorkFlowProcessDao;
import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.common.dto.Page;
import com.gta.edu.sdk.util.StringUtil;

import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * @program: human-manage-parent
 * @description: 流程查询DaoImpl
 * @author: panl
 * @create: 2020-07-03 16:34
 **/
@Repository
public class WorkFlowProcessDaoImpl extends BaseDaoImpl<TOrgDept> implements IWorkFlowProcessDao {
    @Override
    public void queryProcess(ProcessListVo processListVo,Page<ProcessListVo> page,User user) {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        String sql = "SELECT wf.id,wf.business_id,wf.business_type_id,wf.deal_erp_no,wf.create_time," +
                "wf.deal_time,temp.flow_status,mi.MOULD_NAME as business_type_name, " +
                " GET_DIC('FlowAuditStatus',temp.flow_status) as flow_status_name,temp.primitive_id  FROM t_work_flow wf  ";
        StringBuilder sqlbuilder = new StringBuilder(sql);
        if(!StringUtils.isEmpty(processListVo.getTabName())){
            sqlbuilder.append(" LEFT JOIN  ");
            sqlbuilder.append(processListVo.getTabName());
            sqlbuilder.append(" temp ON wf.business_id = temp.id ");
        }
        sqlbuilder.append(" LEFT JOIN t_mould_info mi ON mi.id = wf.business_type_id ");
        sqlbuilder.append(" where 1=1 and wf.del_sign = 0 and temp.del_sign = 0  ");
        if(!StringUtils.isEmpty(processListVo.getBusinessTypeId())){
            sqlbuilder.append(" and  wf.business_type_id = ? ");
            arrayList.add(processListVo.getBusinessTypeId());
        }
        if(!StringUtils.isEmpty(processListVo.getFlowStatus())){
            sqlbuilder.append(" and temp.flow_status = ? ");
            arrayList.add(processListVo.getFlowStatus());
        }
        if(!StringUtils.isEmpty(user.getFax())){
            sqlbuilder.append(" and wf.creater_id = ? ");
            arrayList.add(user.getFax());
        }
        if(!StringUtils.isEmpty(processListVo.getStartTime())){
            sqlbuilder.append(" and wf.create_time >= ? ");
            arrayList.add(new SimpleDateFormat("yyyy-MM-dd").format(processListVo.getStartTime()));
        }
        if(!StringUtils.isEmpty(processListVo.getEndTime())){
            sqlbuilder.append(" and wf.create_time < ? ");
            arrayList.add(new SimpleDateFormat("yyyy-MM-dd").format(processListVo.getEndTime())+" 23:59:59");
        }
        sqlbuilder.append(" order by wf.create_time desc ");
        this.findPageBySql(ProcessListVo.class, sqlbuilder.toString(), page, arrayList.toArray());
    }

    @Override
    @Transactional
    public int deleteProcess(ProcessListVo processListVo) throws Exception{
        String sql = "update t_work_flow set del_sign = 1 ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" where 1=1 ");
        Map<String, Object> params = new HashMap<String, Object>();
        if(!StringUtil.isNullOrEmpty(processListVo.getId())){
            sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR}");
            params.put("id",processListVo.getId());
        }
        String sql2 = "update ";
        StringBuilder sqlBuilder2 = new StringBuilder(sql2);
        if(!StringUtil.isNullOrEmpty(processListVo.getTabName())){
            sqlBuilder2.append(processListVo.getTabName());
        }
        sqlBuilder2.append(" set del_sign = 1 ");
        sqlBuilder2.append(" where 1=1 ");
        Map<String, Object> params2 = new HashMap<String, Object>();
        if(!StringUtil.isNullOrEmpty(processListVo.getBusinessId())){
            sqlBuilder2.append(" and id = #{id,jdbcType=VARCHAR}");
            params2.put("id",processListVo.getBusinessId());
        }
        int num = this.executeSql(sqlBuilder.toString(), params);
        int num2 = 0;
        if(num>0){
            num2 = this.executeSql(sqlBuilder2.toString(), params2);
        }
        return num2;
    }

    @Override
    public int updateTWorkExpInfo(TWorkExpInfo tWorkExpInfo) {
        String sql = "update t_work_exp_info  set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        Map<String, Object> params = new HashMap<String, Object>();
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getUserName())){
            sqlBuilder.append("  user_name = #{user_name,jdbcType=VARCHAR},");
            params.put("user_name",tWorkExpInfo.getUserName());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getIdCardNo())){
            sqlBuilder.append("  id_card_no = #{id_card_no,jdbcType=VARCHAR},");
            params.put("id_card_no",tWorkExpInfo.getIdCardNo());
        }
        if(tWorkExpInfo.getStartDate()!=null){
            sqlBuilder.append("  start_date = #{start_date,jdbcType=VARCHAR},");
            params.put("start_date",tWorkExpInfo.getStartDate());
        }
        if(tWorkExpInfo.getEndDate()!=null){
            sqlBuilder.append("  end_date = #{end_date,jdbcType=VARCHAR},");
            params.put("end_date",tWorkExpInfo.getEndDate());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getCompany())){
            sqlBuilder.append("  company = #{company,jdbcType=VARCHAR},");
            params.put("company",tWorkExpInfo.getCompany());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getDept())){
            sqlBuilder.append("  dept = #{dept,jdbcType=VARCHAR},");
            params.put("dept",tWorkExpInfo.getDept());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getPost())){
            sqlBuilder.append("  post = #{post,jdbcType=VARCHAR},");
            params.put("post",tWorkExpInfo.getPost());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getRank())){
            sqlBuilder.append("  rank = #{rank,jdbcType=VARCHAR},");
            params.put("rank",tWorkExpInfo.getRank());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getJobContent())){
            sqlBuilder.append("  job_content = #{job_content,jdbcType=VARCHAR},");
            params.put("job_content",tWorkExpInfo.getJobContent());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getPostType())){
            sqlBuilder.append("  post_type = #{post_type,jdbcType=VARCHAR},");
            params.put("post_type",tWorkExpInfo.getPostType());
        }
        if(null != tWorkExpInfo.getIsValid()){
            sqlBuilder.append("  is_valid = #{is_valid,jdbcType=INTEGER},");
            params.put("is_valid",tWorkExpInfo.getIsValid());
        }
        if(null != tWorkExpInfo.getFlowStatus()){
            sqlBuilder.append("  flow_status = #{flow_status,jdbcType=INTEGER},");
            params.put("flow_status",tWorkExpInfo.getFlowStatus());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getUpdaterId())){
            sqlBuilder.append("  updater_id = #{updater_id,jdbcType=VARCHAR},");
            params.put("updater_id",tWorkExpInfo.getUpdaterId());
        }
        if(!StringUtil.isNullOrEmpty(tWorkExpInfo.getUpdaterName())){
            sqlBuilder.append("  updater_name = #{updater_name,jdbcType=VARCHAR},");
            params.put("updater_name",tWorkExpInfo.getUpdaterName());
        }
//        if(tWorkExpInfo.getUpdateTime()!=null){
            sqlBuilder.append("  update_time = now() ");
//            params.put("update_time",new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date()));
//        }
        sqlBuilder = new StringBuilder(sqlBuilder.substring(0,sqlBuilder.length()-1));
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        params.put("id",tWorkExpInfo.getId());

        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTSdtTutorPrentInfo(TSdtTutorPrentInfo tSdtTutorPrentInfo) {
        String sql = "update t_sdt_tutor_prent_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("start_date = #{start_date,jdbcType=VARCHAR},")
                .append("end_date = #{end_date,jdbcType=VARCHAR},")
                .append("tutor_name = #{tutor_name,jdbcType=VARCHAR},")
                .append("prent_name = #{prent_name,jdbcType=VARCHAR},")
                .append("teach_summary = #{teach_summary,jdbcType=VARCHAR},")
                .append("id_card_no =#{id_card_no,jdbcType=VARCHAR},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now()");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tSdtTutorPrentInfo.getId());
        params.put("start_date", tSdtTutorPrentInfo.getStartDate());
        params.put("end_date", tSdtTutorPrentInfo.getEndDate());
        params.put("tutor_name", tSdtTutorPrentInfo.getTutorName());
        params.put("prent_name", tSdtTutorPrentInfo.getPrentName());
        params.put("teach_summary", tSdtTutorPrentInfo.getTeachSummary());
        params.put("id_card_no", tSdtTutorPrentInfo.getIdCardNo());
        params.put("is_valid", tSdtTutorPrentInfo.getIsValid());
        params.put("flow_status", tSdtTutorPrentInfo.getFlowStatus());
        params.put("updater_id", tSdtTutorPrentInfo.getUpdaterId());
        params.put("updater_name", tSdtTutorPrentInfo.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTProjAchieveInfo(TProjAchieveInfo tProjAchieveInfo) {
        String sql = "update t_proj_achieve_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("start_date = #{start_date,jdbcType=VARCHAR},")
                .append("end_date = #{end_date,jdbcType=VARCHAR},")
                .append("proj_name = #{proj_name,jdbcType=VARCHAR},")
                .append("summary = #{summary,jdbcType=VARCHAR},")
                .append("proj_level = #{proj_level,jdbcType=VARCHAR},")
                .append("encourage = #{encourage,jdbcType=VARCHAR},")
                .append("part_count=#{part_count,jdbcType=INTEGER}, ")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now()");

        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tProjAchieveInfo.getId());
        params.put("start_date", tProjAchieveInfo.getStartDate());
        params.put("end_date", tProjAchieveInfo.getEndDate());
        params.put("proj_name", tProjAchieveInfo.getProjName());
        params.put("summary", tProjAchieveInfo.getSummary());
        params.put("proj_level", tProjAchieveInfo.getProjLevel());
        params.put("encourage", tProjAchieveInfo.getEncourage());
        params.put("part_count", tProjAchieveInfo.getPartCount());
        params.put("is_valid", tProjAchieveInfo.getIsValid());
        params.put("flow_status", tProjAchieveInfo.getFlowStatus());
        params.put("updater_id", tProjAchieveInfo.getUpdaterId());
        params.put("updater_name", tProjAchieveInfo.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTHonorInfo(THonorInfo tHonorInfo) {
        String sql = "update  t_honor_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("user_name = #{user_name,jdbcType=VARCHAR},")
                .append("id_card_no = #{id_card_no,jdbcType=VARCHAR},")
                .append("acqu_time = #{acqu_time,jdbcType=VARCHAR},")
                .append("honor_title = #{honor_title,jdbcType=VARCHAR},")
                .append("award_org = #{award_org,jdbcType=VARCHAR},")
                .append("honor_level = #{honor_level,jdbcType=VARCHAR},")
                .append("honor_type = #{honor_type,jdbcType=VARCHAR},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tHonorInfo.getId());
        params.put("user_name", tHonorInfo.getUserName());
        params.put("id_card_no", tHonorInfo.getIdCardNo());
        params.put("acqu_time", tHonorInfo.getAcquTime());
        params.put("honor_title", tHonorInfo.getHonorTitle());
        params.put("award_org", tHonorInfo.getAwardOrg());
        params.put("honor_level", tHonorInfo.getHonorLevel());
        params.put("honor_type", tHonorInfo.getHonorType());
        params.put("is_valid", tHonorInfo.getIsValid());
        params.put("flow_status", tHonorInfo.getFlowStatus());
        params.put("updater_id", tHonorInfo.getUpdaterId());
        params.put("updater_name", tHonorInfo.getUpdaterName());

        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTTecManInnov(TTecManInnov tTecManInnov) {
        String sql = "update t_tec_man_innov set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("achi_name = #{achi_name,jdbcType=VARCHAR},")
                .append("achi_type = #{achi_type,jdbcType=VARCHAR},")
                .append("summary = #{summary,jdbcType=VARCHAR},")
                .append("award_name = #{award_name,jdbcType=VARCHAR},")
                .append("award_date = #{award_date,jdbcType=VARCHAR},")
                .append("award_org = #{award_org,jdbcType=VARCHAR},")
                .append("award_level = #{award_level,jdbcType=VARCHAR},")
                .append("award_grade = #{award_grade,jdbcType=VARCHAR},")
                .append("group_name = #{group_name,jdbcType=VARCHAR},")
                .append("member_name = #{member_name,jdbcType=VARCHAR},")
                .append("part_count=#{part_count,jdbcType=INTEGER}, ")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now()");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tTecManInnov.getId());
        params.put("achi_name", tTecManInnov.getAchiName());
        params.put("achi_type", tTecManInnov.getAchiType());
        params.put("summary", tTecManInnov.getSummary());
        params.put("award_name", tTecManInnov.getAwardName());
        params.put("award_date", tTecManInnov.getAwardDate());
        params.put("award_org", tTecManInnov.getAwardOrg());
        params.put("award_level", tTecManInnov.getAwardLevel());
        params.put("award_grade", tTecManInnov.getAwardGrade());
        params.put("group_name", tTecManInnov.getGroupName());
        params.put("member_name", tTecManInnov.getMemberName());
        params.put("part_count", tTecManInnov.getPartCount());
        params.put("is_valid", tTecManInnov.getIsValid());
        params.put("flow_status", tTecManInnov.getFlowStatus());
        params.put("updater_id", tTecManInnov.getUpdaterId());
        params.put("updater_name", tTecManInnov.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTContestInfo(TContestInfo tContestInfo) {
        String sql = "update t_contest_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("user_name = #{user_name,jdbcType=VARCHAR},")
                .append("id_card_no = #{id_card_no,jdbcType=VARCHAR},")
                .append("award_date = #{award_date,jdbcType=VARCHAR},")
                .append("comp_name = #{comp_name,jdbcType=VARCHAR},")
                .append("host_org = #{host_org,jdbcType=VARCHAR},")
                .append("award_name = #{award_name,jdbcType=VARCHAR},")
                .append("award_level = #{award_level,jdbcType=VARCHAR},")
                .append("comp_rank = #{comp_rank,jdbcType=VARCHAR},")
                .append("get_title = #{get_title,jdbcType=VARCHAR},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tContestInfo.getId());
        params.put("user_name", tContestInfo.getUserName());
        params.put("id_card_no", tContestInfo.getIdCardNo());
        params.put("award_date", tContestInfo.getAwardDate());
        params.put("comp_name", tContestInfo.getCompName());
        params.put("host_org", tContestInfo.getHostOrg());
        params.put("award_name", tContestInfo.getAwardName());
        params.put("award_level", tContestInfo.getAwardLevel());
        params.put("comp_rank", tContestInfo.getCompRank());
        params.put("get_title", tContestInfo.getGetTitle());
        params.put("is_valid", tContestInfo.getIsValid());
        params.put("flow_status", tContestInfo.getFlowStatus());
        params.put("updater_id", tContestInfo.getUpdaterId());
        params.put("updater_name", tContestInfo.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTTecInnovInfo(TTecInnovInfo tTecInnovInfo) {
        String sql = "update t_tec_innov_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("award_type = #{award_type,jdbcType=VARCHAR},").append("achi_name = #{achi_name,jdbcType=VARCHAR},")
                .append("sumary = #{sumary,jdbcType=VARCHAR},")
                .append("award_name = #{award_name,jdbcType=VARCHAR},")
                .append("award_date = #{award_date,jdbcType=VARCHAR},")
                .append("award_org = #{award_org,jdbcType=VARCHAR},")
                .append("award_level = #{award_level,jdbcType=VARCHAR},")
                .append("award_grade = #{award_grade,jdbcType=VARCHAR},")
                .append("group_name = #{group_name,jdbcType=VARCHAR},")
                .append("member_name = #{member_name,jdbcType=VARCHAR},")
                .append("part_count=#{part_count,jdbcType=INTEGER}, ")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now()");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tTecInnovInfo.getId());
        params.put("award_type", tTecInnovInfo.getAwardType());
        params.put("achi_name", tTecInnovInfo.getAchiName());
        params.put("sumary", tTecInnovInfo.getSumary());
        params.put("award_name", tTecInnovInfo.getAwardName());
        params.put("award_date", tTecInnovInfo.getAwardDate());
        params.put("award_org", tTecInnovInfo.getAwardOrg());
        params.put("award_level", tTecInnovInfo.getAwardLevel());
        params.put("award_grade", tTecInnovInfo.getAwardGrade());
        params.put("group_name", tTecInnovInfo.getGroupName());
        params.put("member_name", tTecInnovInfo.getMemberName());
        params.put("part_count", tTecInnovInfo.getPartCount());
        params.put("is_valid", tTecInnovInfo.getIsValid());
        params.put("flow_status", tTecInnovInfo.getFlowStatus());
        params.put("updater_id", tTecInnovInfo.getUpdaterId());
        params.put("updater_name", tTecInnovInfo.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTPatentInfo(TPatentInfo tPatentInfo) {
        String sql = "update t_patent_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("patent_name = #{patent_name,jdbcType=VARCHAR},")
                .append("patent_no = #{patent_no,jdbcType=VARCHAR},")
                .append("patent_type = #{patent_type,jdbcType=VARCHAR},")
                .append("apply_date = #{apply_date,jdbcType=VARCHAR},")
                .append("decl_date = #{decl_date,jdbcType=VARCHAR},")
                .append("inventor = #{inventor,jdbcType=VARCHAR},")
                .append("part_count=#{part_count,jdbcType=INTEGER}, ")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tPatentInfo.getId());
        params.put("patent_name", tPatentInfo.getPatentName());
        params.put("patent_no", tPatentInfo.getPatentNo());
        params.put("patent_type", tPatentInfo.getPatentType());
        params.put("apply_date", tPatentInfo.getApplyDate());
        params.put("decl_date", tPatentInfo.getDeclDate());
        params.put("inventor", tPatentInfo.getInventor());
        params.put("part_count", tPatentInfo.getPartCount());
        params.put("is_valid", tPatentInfo.getIsValid());
        params.put("flow_status", tPatentInfo.getFlowStatus());
        params.put("is_valid", tPatentInfo.getIsValid());
        params.put("updater_id", tPatentInfo.getUpdaterId());
        params.put("updater_name", tPatentInfo.getUpdaterName());
        params.put("update_time", new Timestamp(new Date().getTime()));

        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTStandInfo(TStandInfo tStandInfo) {
        String sql = "update t_stand_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("issue_time = #{issue_time,jdbcType=VARCHAR},")
                .append("name = #{name,jdbcType=VARCHAR},")
                .append("type = #{type,jdbcType=VARCHAR},")
                .append("level = #{level,jdbcType=VARCHAR},")
                .append("part_count = #{part_count,jdbcType=INTEGER},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tStandInfo.getId());
        params.put("issue_time", tStandInfo.getIssueTime());
        params.put("name", tStandInfo.getName());
        params.put("type", tStandInfo.getType());
        params.put("level", tStandInfo.getLevel());
        params.put("part_count", tStandInfo.getPartCount());
        params.put("is_valid", tStandInfo.getIsValid());
        params.put("flow_status", tStandInfo.getFlowStatus());
        params.put("updater_id", tStandInfo.getUpdaterId());
        params.put("updater_name", tStandInfo.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTAcadeAchiveInfo(TAcadeAchiveInfo tAcadeAchiveInfo) {
        String sql = "update t_acade_achive_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("pub_time = #{pub_time,jdbcType=VARCHAR},")
                .append("acad_type = #{acad_type,jdbcType=VARCHAR},")
                .append("acad_name = #{acad_name,jdbcType=VARCHAR},")
                .append("summary = #{summary,jdbcType=VARCHAR},")
                .append("pub_name = #{pub_name,jdbcType=VARCHAR},")
                .append("issn = #{issn,jdbcType=VARCHAR},")
                .append("periodic_no = #{periodic_no,jdbcType=VARCHAR},")
                .append("page = #{page,jdbcType=VARCHAR},")
                .append("publisher = #{publisher,jdbcType=VARCHAR},")
                .append("level = #{level,jdbcType=VARCHAR},")
                .append("part_count = #{part_count,jdbcType=INTEGER},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tAcadeAchiveInfo.getId());
        params.put("pub_time", tAcadeAchiveInfo.getPubTime());
        params.put("acad_type", tAcadeAchiveInfo.getAcadType());
        params.put("acad_name", tAcadeAchiveInfo.getAcadName());
        params.put("summary", tAcadeAchiveInfo.getSummary());
        params.put("pub_name", tAcadeAchiveInfo.getPubName());
        params.put("issn", tAcadeAchiveInfo.getIssn());
        params.put("periodic_no", tAcadeAchiveInfo.getPeriodicNo());
        params.put("page", tAcadeAchiveInfo.getPage());
        params.put("publisher", tAcadeAchiveInfo.getPublisher());
        params.put("level", tAcadeAchiveInfo.getLevel());
        params.put("part_count", tAcadeAchiveInfo.getPartCount());
        params.put("flow_status", tAcadeAchiveInfo.getFlowStatus());
        params.put("is_valid", tAcadeAchiveInfo.getIsValid());
        params.put("creater_id", tAcadeAchiveInfo.getCreaterId());
        params.put("creater_name", tAcadeAchiveInfo.getCreaterName());
        params.put("create_time", new Timestamp(new Date().getTime()));
        params.put("updater_id", tAcadeAchiveInfo.getUpdaterId());
        params.put("updater_name", tAcadeAchiveInfo.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTExpertTitleInfo(TExpertTitleInfo tExpertTitleInfo) {
        String sql = "update t_expert_title_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder
                .append("user_name=#{user_name,jdbcType=VARCHAR},")
                .append("id_card_no=#{id_card_no,jdbcType=VARCHAR},")
                .append("major=#{major,jdbcType=VARCHAR},")
                .append("acqu_time=#{acqu_time,jdbcType=VARCHAR},")
                .append("post_time=#{post_time,jdbcType=VARCHAR},")
                .append("level_name=#{level_name,jdbcType=VARCHAR},")
                .append("type=#{type,jdbcType=VARCHAR},")
                .append("emp_term_start=#{emp_term_start,jdbcType=VARCHAR},")
                .append("emp_term_end=#{emp_term_end,jdbcType=VARCHAR},")
                .append("emp_title=#{emp_title,jdbcType=VARCHAR},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id=#{updater_id,jdbcType=VARCHAR},")
                .append("updater_name=#{updater_name,jdbcType=VARCHAR},")
                .append("update_time=now()");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tExpertTitleInfo.getId());
        params.put("user_name", tExpertTitleInfo.getUserName());
        params.put("id_card_no", tExpertTitleInfo.getIdCardNo());
        params.put("major", tExpertTitleInfo.getMajor());
        params.put("acqu_time", tExpertTitleInfo.getAcquTime());
        params.put("post_time", tExpertTitleInfo.getPostTime());
        params.put("level_name", tExpertTitleInfo.getLevelName());
        params.put("type", tExpertTitleInfo.getType());
        params.put("emp_term_start", tExpertTitleInfo.getEmpTermStart());
        params.put("emp_term_end", tExpertTitleInfo.getEmpTermEnd());
        params.put("emp_title", tExpertTitleInfo.getEmpTitle());
        params.put("is_valid", tExpertTitleInfo.getIsValid());
        params.put("flow_status", tExpertTitleInfo.getFlowStatus());
        params.put("updater_id", tExpertTitleInfo.getUpdaterId());
        params.put("updater_name", tExpertTitleInfo.getUpdaterName());
        params.put("update_time", new Timestamp(new Date().getTime()));
        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTSkillLevelInfo(TSkillLevelInfo tSkillLevelInfo) {
        String sql = "update t_skill_level_info set  ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder
                .append("user_name = #{user_name,jdbcType=VARCHAR},")
                .append("id_card_no = #{id_card_no,jdbcType=VARCHAR},")
                .append("acqu_time = #{acqu_time,jdbcType=VARCHAR},")
                .append("post_time = #{post_time,jdbcType=VARCHAR},")
                .append("tech_type = #{tech_type,jdbcType=VARCHAR},")
                .append("qualifi_level = #{qualifi_level,jdbcType=VARCHAR},")
                .append("audit_org = #{audit_org,jdbcType=VARCHAR},")
                .append("org_level = #{org_level,jdbcType=VARCHAR},")
                .append("cert_no = #{cert_no,jdbcType=VARCHAR},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tSkillLevelInfo.getId());
        params.put("user_name", tSkillLevelInfo.getUserName());
        params.put("id_card_no", tSkillLevelInfo.getIdCardNo());
        params.put("acqu_time", tSkillLevelInfo.getAcquTime());
        params.put("post_time", tSkillLevelInfo.getPostTime());
        params.put("tech_type", tSkillLevelInfo.getTechType());
        params.put("qualifi_level", tSkillLevelInfo.getQualifiLevel());
        params.put("audit_org", tSkillLevelInfo.getAuditOrg());
        params.put("org_level", tSkillLevelInfo.getOrgLevel());
        params.put("cert_no", tSkillLevelInfo.getCertNo());
        params.put("is_valid", tSkillLevelInfo.getIsValid());
        params.put("flow_status", tSkillLevelInfo.getFlowStatus());
        params.put("updater_id", tSkillLevelInfo.getUpdaterId());
        params.put("updater_name", tSkillLevelInfo.getUpdaterName());

        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTProTecInfo(TProTecInfo tProTecInfo) {
        String sql = "update t_pro_tec_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder
                .append("user_name=#{user_name,jdbcType=VARCHAR},")
                .append("id_card_no=#{id_card_no,jdbcType=VARCHAR},")
                .append("acqu_time=#{acqu_time,jdbcType=VARCHAR},")
                .append("post_time=#{post_time,jdbcType=VARCHAR},")
                .append("subj_name=#{subj_name,jdbcType=VARCHAR},")
                .append("subj_set=#{subj_set,jdbcType=VARCHAR},")
                .append("subj_level=#{subj_level,jdbcType=VARCHAR},")
                .append("audit_org=#{audit_org,jdbcType=VARCHAR},")
                .append("org_level=#{org_level,jdbcType=VARCHAR},")
                .append("cert_no=#{cert_no,jdbcType=VARCHAR},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tProTecInfo.getId());
        params.put("user_name", tProTecInfo.getUserName());
        params.put("id_card_no", tProTecInfo.getIdCardNo());
        params.put("acqu_time", tProTecInfo.getAcquTime());
        params.put("post_time", tProTecInfo.getPostTime());
        params.put("subj_name", tProTecInfo.getSubjName());
        params.put("subj_set", tProTecInfo.getSubjSet());
        params.put("subj_level", tProTecInfo.getSubjLevel());
        params.put("audit_org", tProTecInfo.getAuditOrg());
        params.put("org_level", tProTecInfo.getOrgLevel());
        params.put("cert_no", tProTecInfo.getCertNo());
        params.put("is_valid", tProTecInfo.getIsValid());
        params.put("flow_status", tProTecInfo.getFlowStatus());
        params.put("updater_id", tProTecInfo.getUpdaterId());
        params.put("updater_name", tProTecInfo.getUpdaterName());

        return this.executeSql(sqlBuilder.toString(),params);
    }

    @Override
    public int updateTContiStudyInfo(TContiStudyInfo tContiStudyInfo) {
        String sql = "update t_conti_study_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder
                .append("start_time=#{start_time,jdbcType=VARCHAR},")
                .append("end_time=#{end_time,jdbcType=VARCHAR},")
                .append("major=#{major,jdbcType=VARCHAR},")
                .append("study_place=#{study_place,jdbcType=VARCHAR},")
                .append("certifier=#{certifier,jdbcType=VARCHAR},")
                .append("erp_no=#{erp_no,jdbcType=VARCHAR},")
                .append("user_name=#{user_name,jdbcType=VARCHAR},")
                .append("id_card_no=#{id_card_no,jdbcType=VARCHAR},")
                .append("type=#{type,jdbcType=VARCHAR},")
                .append("level=#{level,jdbcType=VARCHAR},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id=#{updater_id,jdbcType=VARCHAR},")
                .append("updater_name=#{updater_name,jdbcType=VARCHAR},")
                .append("update_time=now()");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tContiStudyInfo.getId());
        params.put("start_time", tContiStudyInfo.getStartTime());
        params.put("end_time", tContiStudyInfo.getEndTime());
        params.put("major", tContiStudyInfo.getMajor());
        params.put("study_place", tContiStudyInfo.getStudyPlace());
        params.put("certifier", tContiStudyInfo.getCertifier());
        params.put("erp_no", tContiStudyInfo.getErpNo());
        params.put("user_name", tContiStudyInfo.getUserName());
        params.put("id_card_no", tContiStudyInfo.getIdCardNo());
        params.put("type", tContiStudyInfo.getType());
        params.put("level", tContiStudyInfo.getLevel());
        params.put("is_valid", tContiStudyInfo.getIsValid());
        params.put("flow_status", tContiStudyInfo.getFlowStatus());
        params.put("updater_id", tContiStudyInfo.getUpdaterId());
        params.put("updater_name", tContiStudyInfo.getUpdaterName());

        return this.executeSql(sqlBuilder.toString(),params);
    }

    /**
   	 * 挂职轮岗
   	 * @author yangwang
   	 * @param tRotationInfo
   	 * @return int
   	 *  */
    @Override
    public int updateTRotationInfo(TRotationInfo tRotationInfo) {
    	String sql = "update t_rotation_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder
                .append("start_time=#{start_time,jdbcType=VARCHAR},")
                .append("end_time=#{end_time,jdbcType=VARCHAR},")
                .append("rotation_dept=#{rotation_dept,jdbcType=VARCHAR},")
                .append("rotation_org=#{rotation_org,jdbcType=VARCHAR},")
                .append("rotation_post=#{rotation_post,jdbcType=VARCHAR},")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("updater_id=#{updater_id,jdbcType=VARCHAR},")
                .append("updater_name=#{updater_name,jdbcType=VARCHAR},")
                .append("update_time=now()");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tRotationInfo.getId());
        params.put("start_time", tRotationInfo.getStartTime());
        params.put("end_time", tRotationInfo.getEndTime());
        params.put("rotation_dept", tRotationInfo.getRotationDept());
        params.put("rotation_org", tRotationInfo.getRotationOrg());
        params.put("rotation_post", tRotationInfo.getRotationPost());
        params.put("is_valid", tRotationInfo.getIsValid());
        params.put("flow_status", tRotationInfo.getFlowStatus());
        params.put("updater_id", tRotationInfo.getUpdaterId());
        params.put("updater_name", tRotationInfo.getUpdaterName());

        return this.executeSql(sqlBuilder.toString(),params);
    }

	@Override
	public List<DbCount> queryBusinessTypeLsit(User user) {
		// TODO Auto-generated method stub
		ArrayList<Object> arrayList = new ArrayList<Object>();
        String sql = " SELECT * FROM(SELECT a.id AS business_type_id, a.MOULD_NAME AS business_type_name, count(*) AS db_count, a.tab_name,a.sort ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" FROM t_mould_info a LEFT JOIN t_work_flow b ON a.id = b.business_type_id WHERE b.del_sign=0 and b.creater_id =?  ");
        arrayList.add(user.getFax());
        sqlBuilder.append(" GROUP BY business_type_id ) AS a WHERE a.db_count > 0 ORDER BY sort ");

        return this.findAllBySQL(DbCount.class, sqlBuilder.toString(), null, false, arrayList.toArray());
	}

	@Override
	public int updateTEmployeeMobility(TEmployeeMobility employeeMobility) {
		StringBuilder sqlBuilder = new StringBuilder("update t_employee_mobility set ");
		sqlBuilder.append("flow_mode = #{flow_mode,jdbcType=VARCHAR},")
				.append("flow_area = #{flow_area,jdbcType=VARCHAR},").append("flow_type = #{flow_type,jdbcType=VARCHAR},")
				.append("begin_time = #{begin_time,jdbcType=DATE},").append("end_time = #{end_time,jdbcType=DATE},")
				.append("updater_id = creater_id,").append("updater_name = creater_name,")
				.append("update_time = #{update_time,jdbcType=DATE} ").append("where id = #{id,jdbcType=VARCHAR}");
		HashMap<String, Object> params = new HashMap<>();
		params.put("id",employeeMobility.getId());
		params.put("flow_mode",employeeMobility.getFlowMode());
		params.put("flow_area",employeeMobility.getFlowArea());
		params.put("flow_type",employeeMobility.getFlowType());
		params.put("begin_time",employeeMobility.getBeginTime());
		params.put("end_time",employeeMobility.getEndTime());
		params.put("update_time",LocalDateTime.now());
		return this.executeSql(sqlBuilder.toString(), params);
	}

    @Override
    public int updateTecStandardInfo(TTecStandardInfo tecStandardInfo){
        String sql = "update t_tec_standard_info set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("standard_name = #{standard_name,jdbcType=VARCHAR},")
                .append("standard_type = #{standard_type,jdbcType=VARCHAR},")
                .append("summary = #{summary,jdbcType=VARCHAR},")
                .append("award_date = #{award_date,jdbcType=DATE},")
                .append("post_time = #{post_time,jdbcType=DATE},")
                .append("part_count = #{part_count,jdbcType=INTEGER},")
                .append("is_valid=#{is_valid,jdbcType=INTEGER}, ")
                .append("flow_status=#{flow_status,jdbcType=INTEGER}, ")
                .append("updater_id = #{updater_id,jdbcType=VARCHAR},")
                .append("updater_name = #{updater_name,jdbcType=VARCHAR},")
                .append("update_time = now() ");
        sqlBuilder.append(" where 1=1 ");
        sqlBuilder.append(" and id = #{id,jdbcType=VARCHAR} ");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", tecStandardInfo.getId());
        params.put("standard_name", tecStandardInfo.getStandardName());
        params.put("standard_type", tecStandardInfo.getStandardType());
        params.put("summary", tecStandardInfo.getSummary());
        params.put("award_date", tecStandardInfo.getAwardDate());
        params.put("post_time", tecStandardInfo.getPostTime());
        params.put("part_count", tecStandardInfo.getPartCount());
        params.put("flow_status", tecStandardInfo.getFlowStatus());
        params.put("is_valid", tecStandardInfo.getIsValid());
        params.put("creater_id", tecStandardInfo.getCreaterId());
        params.put("creater_name", tecStandardInfo.getCreaterName());
        params.put("create_time", new Timestamp(new Date().getTime()));
        params.put("updater_id", tecStandardInfo.getUpdaterId());
        params.put("updater_name", tecStandardInfo.getUpdaterName());
        return this.executeSql(sqlBuilder.toString(),params);
    }
}
